package com.diy.sigmund.diyorder.common.middleware.mq.rocketmq.spring.one;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQReplyListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * <br>RPC消息
 * <br>实现RocketMQReplyListener接口
 * <br>申明泛型对象即业务对象
 * <br>申明返回泛型的对象
 * <br>使用@RocketMQMessageListener注解
 * <br>配置@RocketMQMessageListener注
 * <br>必须配置项入下
 * <br>group
 * <br>topic
 * <br>messageModel 设为 MessageModel.BROADCASTING
 * <br>使用@Component注解或者子注解
 * <br>实现接口方法
 *
 * @author ylm-sigmund
 * @since 2022/5/5 22:25
 */
@Component
@RocketMQMessageListener(
        topic = "${topic.sendAndReceive}",
        consumerGroup = "${group.consumer.sendAndReceiveGeneric}",
        selectorExpression = "*")
public class ReceiveGenericConsumer implements RocketMQReplyListener<Object, ResultMsg> {

    private static final Logger log = LoggerFactory.getLogger(ReceiveGenericConsumer.class);

    @Override
    public ResultMsg onMessage(Object message) {
        log.info(String.format("ReceiveGenericConsumer name is %s data is %s", this.getClass().getSimpleName(),
                message));
        return ResultMsg.success(message);
    }

}
